package thread;


import java.util.concurrent.ThreadLocalRandom;

public class ThreadDemo22 {
    public static void main(String[] args) {
        Object A = new Object();
        Object B = new Object();

        Thread t1 = new Thread(()->{
           synchronized (A){
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               } // 演示两个锁 两个线程出现死锁的情况
               synchronized (B){
                   System.out.println("t1拿到了两把锁");
               }
           }
        });

        Thread t2 = new Thread(()->{
            synchronized (B){
                synchronized (A){
                    System.out.println("t2拿到了两把锁");
                }
            }
        });

        t1.start();
        t2.start();
    }
}
